home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / strings / copyrght.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  1.9 KB  |  74 lines

  1. ;void  copy_right(strg,return_strg,number_chars);
  2. ;  char  *strg,*return_strg;
  3. ;  unsigned short  number_chars;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _error_code:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _copy_right
  11. _copy_right proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push si            ;
  16.     push ds            ;
  17.     cmp  _memory_model,0    ;near or far?
  18.     jle  begin        ;jump if near
  19.     inc  bp            ;else add 2 to BP
  20.     inc  bp            ;
  21. begin:    cmp  _memory_model,2    ;data near or far?
  22.     jb   L0            ;jump if near    
  23.     lds  si,dword ptr[bp+8]  ;DS:SI pts to return strg
  24.     les  di,dword ptr[bp+4]  ;ES:DI pts to source strg
  25.     mov  bx,[bp+12]        ;number chars
  26.     jmp  short L1        ;
  27. L0:    mov  si,[bp+6]        ;NEAR case
  28.     mov  di,[bp+4]        ;
  29.     mov  bx,[bp+8]        ;
  30.     mov  ax,ds        ;ES = DS
  31.     mov  es,ax        ;
  32. L1:    mov  bp,1        ;errorcode 1 = strg is null
  33.     mov  byte ptr [si],0    ;return null string if error
  34.     cmp  byte ptr es:[di],0 ;null?
  35.     je   L2            ;quit if so
  36.     or   bx,bx        ;number_chars zero?
  37.     jz   L2            ;quit if so
  38.     inc  bp            ;errorcode 2 = number_chars too large
  39.     mov  cx,0ffffh        ;counter
  40.     mov  dx,di        ;copy strg start position
  41.     cld            ;will search for end of string
  42.     mov  al,0        ;seek null
  43.     repne scasb        ;go find end
  44.     dec  di            ;point back to terminator
  45.     sub  dx,di        ;figure string length
  46.     neg  dx            ;
  47.     cmp  dx,bx        ;number_chars within string length?
  48.     jb   L2            ;
  49.     mov  bp,0        ;errorcode 0 = no error
  50.     add  si,bx        ;point SI to end of return string
  51.     inc  bx            ;number chars, plus 1 for null
  52.     xchg di,si        ;exchange ptrs
  53.     mov  ax,ds        ;
  54.     push es            ;
  55.     mov  es,ax        ;
  56.     pop  ds            ;
  57.     mov  cx,bx        ;counter
  58.     std            ;reverse direction 
  59.     rep  movsb        ;
  60.     cld            ;reset direction
  61. L2:    pop  ds            ;restore DS
  62.     mov  ax,bp        ;fetch errorcode
  63.     mov  _error_code,al    ;set it
  64.     pop  si            ;
  65.     pop  di            ;
  66.     pop  bp            ;
  67.     cmp  _memory_model,0    ;quit
  68.     jle  quit        ;
  69.     db   0CBh        ;RET far
  70. quit:    ret            ;RET near
  71. _copy_right ENDP
  72. _TEXT    ENDS
  73.     END
  74.